import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDShop {
	/**ID--1集市2流浪商人*/
	id,
	/**商店类型入口--1.集市(世界地图)--2.流浪商人(左侧图标)--3. 竞技场商店--4. 随机事件神秘商人--5. 观影礼包*/
	type,
	/**功能解锁id--FunctionUnlock*/
	unlockid,
	/**名称*/
	name,
	/**banner图*/
	banner,
	/**商品数量--0表示固定商店-->0表示随机商店，商品的个数*/
	goodsNum,
	/**图标*/
	icon,
	/**标题*/
	title,
	/**描述--配置商店最下方描述文字*/
	desc,
	/**免费刷新初始次数*/
	initFreeRefreshNum,
	/**最大刷新次数--0无次数*/
	refreshMaxNum,
	/**免费刷新恢复时间（秒）*/
	freeRefreshTime,
	/**刷新消耗道具ID(道具id)*/
	refreshItemId,
	/**购买商品消耗资源ID(道具id)*/
	costItemId,
	/**活动类型--指定活动开启*/
	activityType,
	/**显示道具类型--0.直接显示道具--1.读取服务器下发//远征--2.根据活动id显示道具*/
	showItem,

	/**枚举数量*/
	EnumCount
}



export class CDShop{
	/**ID--1集市2流浪商人*/
	public id: number;
	/**商店类型入口--1.集市(世界地图)--2.流浪商人(左侧图标)--3. 竞技场商店--4. 随机事件神秘商人--5. 观影礼包*/
	public type: number;
	/**功能解锁id--FunctionUnlock*/
	public unlockid: number;
	/**名称*/
	public name: number;
	/**banner图*/
	public banner: string;
	/**商品数量--0表示固定商店-->0表示随机商店，商品的个数*/
	public goodsNum: number;
	/**图标*/
	public icon: number;
	/**标题*/
	public title: number;
	/**描述--配置商店最下方描述文字*/
	public desc: number;
	/**免费刷新初始次数*/
	public initFreeRefreshNum: number;
	/**最大刷新次数--0无次数*/
	public refreshMaxNum: number;
	/**免费刷新恢复时间（秒）*/
	public freeRefreshTime: number;
	/**刷新消耗道具ID(道具id)*/
	public refreshItemId: number;
	/**购买商品消耗资源ID(道具id)*/
	public costItemId: number;
	/**活动类型--指定活动开启*/
	public activityType: number;
	/**显示道具类型--0.直接显示道具--1.读取服务器下发//远征--2.根据活动id显示道具*/
	public showItem: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDShop.id: return this.id;
			case E_CDShop.type: return this.type;
			case E_CDShop.unlockid: return this.unlockid;
			case E_CDShop.name: return this.name;
			case E_CDShop.banner: return this.banner;
			case E_CDShop.goodsNum: return this.goodsNum;
			case E_CDShop.icon: return this.icon;
			case E_CDShop.title: return this.title;
			case E_CDShop.desc: return this.desc;
			case E_CDShop.initFreeRefreshNum: return this.initFreeRefreshNum;
			case E_CDShop.refreshMaxNum: return this.refreshMaxNum;
			case E_CDShop.freeRefreshTime: return this.freeRefreshTime;
			case E_CDShop.refreshItemId: return this.refreshItemId;
			case E_CDShop.costItemId: return this.costItemId;
			case E_CDShop.activityType: return this.activityType;
			case E_CDShop.showItem: return this.showItem;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDShop.id: this.id = v; break;
			case E_CDShop.type: this.type = v; break;
			case E_CDShop.unlockid: this.unlockid = v; break;
			case E_CDShop.name: this.name = v; break;
			case E_CDShop.banner: this.banner = v; break;
			case E_CDShop.goodsNum: this.goodsNum = v; break;
			case E_CDShop.icon: this.icon = v; break;
			case E_CDShop.title: this.title = v; break;
			case E_CDShop.desc: this.desc = v; break;
			case E_CDShop.initFreeRefreshNum: this.initFreeRefreshNum = v; break;
			case E_CDShop.refreshMaxNum: this.refreshMaxNum = v; break;
			case E_CDShop.freeRefreshTime: this.freeRefreshTime = v; break;
			case E_CDShop.refreshItemId: this.refreshItemId = v; break;
			case E_CDShop.costItemId: this.costItemId = v; break;
			case E_CDShop.activityType: this.activityType = v; break;
			case E_CDShop.showItem: this.showItem = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDShop> = new HashMap<number, CDShop>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDShop[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDShop();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].type = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].unlockid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].banner = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].goodsNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].title = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].initFreeRefreshNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].refreshMaxNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].freeRefreshTime = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].refreshItemId = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costItemId = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].activityType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].showItem = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDShop{
		return this.datas ? this.datas.get(id) : null;
	}
}
